import os

def check_file_exist(filename, msg_tmpl='file "{}" does not exist'):
    if not os.path.exists(filename):
        raise FileNotFoundError(msg_tmpl.format(filename))

def listsortdir(dir_path:str):
    check_file_exist(dir_path)
    sudirs = os.listdir(dir_path)
    sudirs.sort(key=lambda x: x)
    return sudirs

def mkdir_or_exist(dir_name, mode=0o777):
    if dir_name == '':
        return
    dir_name = os.path.expanduser(dir_name)
    os.makedirs(dir_name, mode=mode, exist_ok=True)

def symlink(src, dst, overwrite=True, **kwargs):
    if os.path.lexists(dst) and overwrite:
        os.remove(dst)
    os.symlink(src, dst, **kwargs)